﻿<form id="org-meal-form" lay-filter="org-meal-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <input name="state" type="hidden" value="1"/>
    <div class="layui-form-item">
        <label class="layui-form-label">套餐名称</label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入套餐名称" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">套餐价格</label>
        <div class="layui-input-block">
            <input name="price" placeholder="请输入套餐价格" type="text" class="layui-input" maxlength="20"
                   lay-verify="required|number" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职员数量</label>
        <div class="layui-input-block">
            <input name="jobberCount" placeholder="请输入职员数量" type="text" class="layui-input"    />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">客户数量</label>
        <div class="layui-input-block">
            <input name="channelCount" placeholder="请输入客户数量" type="text" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">短信次数</label>
        <div class="layui-input-block">
            <input name="msgCount" placeholder="请输入短信次数" type="text" class="layui-input"
            />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">定位次数</label>
        <div class="layui-input-block">
            <input name="positionCount" placeholder="请输入短信次数" type="text" class="layui-input"
            />
        </div>
    </div>

    <div  style="display: none">
        <button class="layui-btn" lay-filter="org-meal-submit" id = "org-meal-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'form', 'formSelects', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var admin = layui.admin;
        form.render("radio","org-meal-form");
        form.render("select","org-meal-form");
        admin.reqBackground("system/role/list",{},function(data){
            if(data && data.length){
                var obj = admin.getTempData("org-meal-form-obj");
                if(obj && obj.role) {
                    var roleIds = obj.role.split(",");
                }
                for(var i=0;i<data.length;i++){
                    data[i]['value'] = data[i]['id'];
                    if(obj && obj.role){
                        for(var j = 0;j<roleIds.length;j++){
                            if(data[i].id == roleIds[j]){
                                data[i].selected = 'selected';
                                break;
                            }
                        }
                    }
                }
                formSelects.data("org-meal-form-role","local",{arr:data});
            }
        })
        var url = 'org/meal/add';  //实际项目这里是添加用户的url
        // 回显user数据
        var user = admin.getTempData('org-meal-form-obj');
        if (user) {
            $('#org-meal-form input[name="account"]').attr('readonly', 'readonly');
            url = 'system/user/update';  // 实际项目这里是修改用户的url
            form.val('org-meal-form', user);
            // var rds = new Array();
            // for (var i = 0; i < user.roles.length; i++) {
            //     rds.push(user.roles[i].roleId);
            // }
            // formSelects.value('roleId', rds);
        }

        // 表单提交事件
        form.on('submit(org-meal-submit)', function (data) {
            admin.req(url, data.field, function (data) {
                layer.msg("保存成功", {icon: 1});
                admin.putTempData('org-meal-formOk', true);  // 操作成功刷新表格
                layer.close(layer.curr_idex)
            },"post");
            return false;
        });
    });
</script>

</body>
</html>